package com.gemme.gemme.util;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.gemme.gemme.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class ImageLoaderUtil {
    private static ImageLoaderUtil mInstance;

    protected ImageLoaderUtil() {
    }

    public static ImageLoaderUtil getInstance() {
        if (mInstance == null) {
            synchronized (ImageLoaderUtil.class) {
                if (mInstance == null) {
                    mInstance = new ImageLoaderUtil();
                }
            }
        }
        return mInstance;
    }

    /**
     * 加载圆形网络图片
     *
     * @param imagePath  图片地址
     * @param imageView  图片视图
     * @param loadingUri 加载中图片
     * @param emptyUri   空白期图片
     * @param failUri    失败图片
     */
    public void LoadCircleImage(final String imagePath, final ImageView imageView, final int loadingUri, final int emptyUri, final int failUri) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(loadingUri)
                .showImageForEmptyUri(emptyUri)
                .showImageOnFail(failUri)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new RoundedBitmapDisplayer(180)).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载圆形网络图片
     *
     * @param imagePath 图片地址
     * @param imageView 图片视图
     * @param imageUri  处理图片
     */
    public void LoadCircleImage(final String imagePath, final ImageView imageView, final int imageUri) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(imageUri)
                .showImageForEmptyUri(imageUri)
                .showImageOnFail(imageUri)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new RoundedBitmapDisplayer(180)).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载圆形网络图片
     *
     * @param imagePath 图片地址
     * @param imageView 图片视图
     */
    public void LoadCircleImage(final String imagePath, final ImageView imageView) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.pc_default)
                .showImageForEmptyUri(R.drawable.pc_default)
                .showImageOnFail(R.drawable.pc_default)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new RoundedBitmapDisplayer(180)).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载带弧度网络图片
     *
     * @param imagePath  图片地址
     * @param imageView  图片视图
     * @param loadingUri 加载中图片
     * @param emptyUri   空白期图片
     * @param failUri    失败图片
     * @param radian     图片弧度
     */
    public void LoadRadianImage(final String imagePath, final ImageView imageView, final int loadingUri, final int emptyUri, final int failUri, final int radian) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(loadingUri)
                .showImageForEmptyUri(emptyUri)
                .showImageOnFail(failUri)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new RoundedBitmapDisplayer(radian)).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载带弧度网络图片
     *
     * @param imagePath 图片地址
     * @param imageView 图片视图
     * @param imageUri  处理图片
     * @param radian    图片弧度
     */
    public void LoadRadianImage(final String imagePath, final ImageView imageView, final int imageUri, final int radian) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(imageUri)
                .showImageForEmptyUri(imageUri)
                .showImageOnFail(imageUri)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new RoundedBitmapDisplayer(radian)).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载带弧度网络图片
     *
     * @param imagePath 图片地址
     * @param imageView 图片视图
     * @param radian    图片弧度
     */
    public void LoadRadianImage(final String imagePath, final ImageView imageView, final int radian) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.pc_default)
                .showImageForEmptyUri(R.drawable.pc_default)
                .showImageOnFail(R.drawable.pc_default)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new RoundedBitmapDisplayer(radian)).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载网络图片
     *
     * @param imagePath  图片地址
     * @param imageView  图片视图
     * @param loadingUri 加载中图片
     * @param emptyUri   空白期图片
     * @param failUri    失败图片
     */
    public void LoadImage(final String imagePath, final ImageView imageView, final int loadingUri, final int emptyUri, final int failUri) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(loadingUri)
                .showImageForEmptyUri(emptyUri)
                .showImageOnFail(failUri)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载网络图片
     *
     * @param imagePath 图片地址
     * @param imageView 图片视图
     * @param imageUri  处理图片
     */
    public void LoadImage(final String imagePath, final ImageView imageView, final int imageUri) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(imageUri)
                .showImageForEmptyUri(imageUri)
                .showImageOnFail(imageUri)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }

    /**
     * 加载网络图片
     *
     * @param imagePath 图片地址
     * @param imageView 图片视图
     */
    public void LoadImage(final String imagePath, final ImageView imageView) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.pc_default)
                .showImageForEmptyUri(R.drawable.pc_default)
                .showImageOnFail(R.drawable.pc_default)
                .cacheInMemory(true).cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(imagePath, imageView, options);
    }
}